// import { getOrder } from '@utils/get_order'
const state = {
    orderList: [],
    currentPage: 1,
    pageSize: 5,
    tabNav: '近三个月订单'
};

const mutations = {
    select_order(state, val) {
        state.orderList = val
    },
    cut_page(state, val) {
        state.currentPage = val
    },
    cut_size(state, val) {
        state.pageSize = val
    },
    search_order(state, val) {
        state.orderList = val
    },
    set_tabNav(state, val) {
        state.tabNav = val
    }
};

const actions = {
    //获取订单
    // async obtainOrder() {
    //     return await getOrder()
    // },

    //筛选订单
    set_order({ commit }, type) {

        // let data = this.obtainOrder()

        let data = [
            {
                "ord_num": "810009",
                "username": "老王",
                "tel": "15896325874",
                "price": 88,
                "num": 2,
                "state": 1, //0交易关闭 1等待付款 2已经付款(等待处理发货) 3申请退款(等待处理) 4退款成功  5交易成功
                "time": "2021-03-31 12:02:40",
                "pay_time": "2021-03-31 12:02:40",
                "game": "英雄联盟",
                "game_area": "比尔吉沃特",
                "game_num": "414054177",
                "pay_method": "余额支付",
                "area": "广东省 深圳市 福田区 豪强北街道"
            },
            {
                "ord_num": "800108",
                "username": "老李",
                "tel": "15896325874",
                "price": 88,
                "num": 3,
                "state": 1,
                "time": "2021-04-04 12:02:40",
                "pay_time": "2021-03-31 12:02:40",
                "game": "英雄联盟",
                "game_area": "比尔吉沃特",
                "game_num": "414054177",
                "pay_method": "余额支付",
                "area": "广东省 深圳市 福田区 豪强北街道"
            },
            {
                "ord_num": "810006",
                "username": "老王",
                "tel": "15896325874",
                "price": 88,
                "num": 4,
                "state": 2,
                "time": "2021-03-21 12:02:40",
                "pay_time": "",
                "game": "英雄联盟",
                "game_area": "比尔吉沃特",
                "game_num": "414054177",
                "pay_method": "余额支付",
                "area": "广东省 深圳市 福田区 豪强北街道"
            },
            {
                "ord_num": "80306",
                "username": "老李",
                "tel": "15896325874",
                "price": 88,
                "num": 1,
                "state": 3,
                "time": "2021-01-01 12:02:40",
                "pay_time": "2021-03-31 12:02:40",
                "game": "英雄联盟",
                "game_area": "比尔吉沃特",
                "game_num": "414054177",
                "pay_method": "余额支付",
                "area": "广东省 深圳市 福田区 豪强北街道"
            },
            {
                "ord_num": "82006",
                "username": "老王",
                "tel": "2021-01-03 12:02:40",
                "pay_time": "2021-03-31 12:02:40",
                "price": 88,
                "num": 2,
                "state": 2,
                "time": "2021-01-21 12:02:40",
                "game": "英雄联盟",
                "game_area": "比尔吉沃特",
                "game_num": "414054177",
                "pay_method": "余额支付",
                "area": "广东省 深圳市 福田区 豪强北街道"
            },
            {
                "ord_num": "80206",
                "username": "老王",
                "tel": "15896325874",
                "price": 88,
                "num": 3,
                "state": 4,
                "time": "2021-02-21 12:02:40",
                "pay_time": "2021-03-31 12:02:40",
                "game": "英雄联盟",
                "game_area": "比尔吉沃特",
                "game_num": "414054177",
                "pay_method": "余额支付",
                "area": "广东省 深圳市 福田区 豪强北街道"
            },
            {
                "ord_num": "80009",
                "username": "老王",
                "tel": "15896325874",
                "price": 88,
                "num": 2,
                "state": 0,
                "time": "2021-03-31 12:02:40",
                "pay_time": "",
                "game": "英雄联盟",
                "game_area": "比尔吉沃特",
                "game_num": "414054177",
                "pay_method": "余额支付",
                "area": "广东省 深圳市 福田区 豪强北街道"
            },
            {
                "ord_num": "80008",
                "username": "老王",
                "tel": "15896325874",
                "price": 88,
                "num": 1,
                "state": 1,
                "time": "2021-04-04 12:02:40",
                "pay_time": "2021-03-31 12:02:40",
                "game": "英雄联盟",
                "game_area": "比尔吉沃特",
                "game_num": "414054177",
                "pay_method": "余额支付",
                "area": "广东省 深圳市 福田区 豪强北街道"
            },
            {
                "ord_num": "80006",
                "username": "老王",
                "tel": "15896325874",
                "price": 88,
                "num": 2,
                "state": 0,
                "time": "2021-03-21 12:02:40",
                "pay_time": "",
                "game": "英雄联盟",
                "game_area": "比尔吉沃特",
                "game_num": "414054177",
                "pay_method": "余额支付",
                "area": "广东省 深圳市 福田区 豪强北街道"
            },
            {
                "ord_num": "803306",
                "username": "老王",
                "tel": "15896325874",
                "price": 88,
                "num": 2,
                "state": 4,
                "time": "2021-01-01 12:02:40",
                "pay_time": "2021-03-31 12:02:40",
                "game": "英雄联盟",
                "game_area": "比尔吉沃特",
                "game_num": "414054177",
                "pay_method": "余额支付",
                "area": "广东省 深圳市 福田区 豪强北街道"
            },
            {
                "ord_num": "820106",
                "username": "老王",
                "tel": "2021-03-03 12:02:40",
                "pay_time": "2021-03-31 12:02:40",
                "price": 88,
                "num": 2,
                "state": 2,
                "time": "2021-03-01 12:02:40",
                "game": "英雄联盟",
                "game_area": "比尔吉沃特",
                "game_num": "414054177",
                "pay_method": "余额支付",
                "area": "广东省 深圳市 福田区 豪强北街道"
            },
            {
                "ord_num": "802106",
                "username": "老王",
                "tel": "15896325874",
                "price": 88,
                "num": 2,
                "state": 3,
                "time": "2021-02-21 12:02:40",
                "pay_time": "2021-03-31 12:02:40",
                "game": "英雄联盟",
                "game_area": "比尔吉沃特",
                "game_num": "414054177",
                "pay_method": "余额支付",
                "area": "广东省 深圳市 福田区 豪强北街道"
            },
            {
                "ord_num": "823106",
                "username": "老王",
                "tel": "2021-03-03 12:02:40",
                "pay_time": "2021-03-31 12:02:40",
                "price": 88,
                "num": 2,
                "state": 0,
                "time": "2021-02-01 12:02:40",
                "game": "英雄联盟",
                "game_area": "比尔吉沃特",
                "game_num": "414054177",
                "pay_method": "余额支付",
                "area": "广东省 深圳市 福田区 豪强北街道"
            },
            {
                "ord_num": "802136",
                "username": "老王",
                "tel": "15896325874",
                "price": 88,
                "num": 2,
                "state": 1,
                "time": "2021-02-21 12:02:40",
                "pay_time": "2021-03-31 12:02:40",
                "game": "英雄联盟",
                "game_area": "比尔吉沃特",
                "game_num": "414054177",
                "pay_method": "余额支付",
                "area": "广东省 深圳市 福田区 豪强北街道"
            }
        ]
        let dataList = []
        switch (type) {
            case "近三个月订单":
                dataList = data.filter(item => {
                    let now = new Date().getTime()
                    return (now - new Date(item.time).getTime()) < 7776000000
                })
                break;
            case "等待买家付款":
                dataList = data.filter(item => item.state === 0)
                break;
            case "买家已付款":
                dataList = data.filter(item => item.state === 1)
                break;
            case "申请退款":
                dataList = data.filter(item => item.state === 2)
                break;
            case "退款中":
                dataList = data.filter(item => item.state === 3)
                break;
            case "已关闭订单":
                dataList = data.filter(item => item.state === 4)
                break;
            default:
                break;
        }
        commit('select_order', dataList)
    },

    set_page({ commit }, val) {
        commit('cut_page', val)
    },
    set_size({ commit }, val) {
        commit('cut_size', val)
    },
    select_tabNav({ commit }, val) {
        commit('set_tabNav', val)
    }
};
export default {
    namespaced: true,
    state,
    mutations,
    actions
}
